/**
 * This file is part of won-uploader.
 *
 * Author: Daniel K.
 *
 * won-uploader is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * won-uploader is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with won-uploader. If not, see <http://www.gnu.org/licenses/>.
 */

function centerWindow(delay)
{
	var win = $("#wonu-login-main");
	
	var width  = win.width()/2;
	
	var d = ( delay == undefined) ? 600 : delay;
	
	win.animate(
			{
				"margin-left": "-"+width+"px",
				top: 200
			}, d
			);
}

function validateSubmit()
{
	if( $("#username").val() == "" || $("#password").val() == "" )
	{
		$("#error-dialog").dialog("open");
		return false;
	}
	
	return true;
}

function initLogin()
{
	centerWindow(0);
	
	var login = $("#wonu-login");
	var height = login.height();
	
	login.css("height","0px");
	login.css("opacity","0");
	login.delay(200).animate( { 
		height: height+"px",
		opacity: 1 
		}, 500);
	
	$("#loginform").on("submit",
		function() { return validateSubmit(); }
	);
}